﻿Imports HierarchicalGrid

Public Class TreeGrid
    Public ProcName() As String
    Public Params() As Object
    Public displaycolumn As New List(Of String)
    Public nGroupcolumn As New List(Of GroupColumn)
    Private Function GetAllEqual(ByVal proc As String, ByVal param() As Object) As DataTable
        Dim dt As New DataTable
        If Utils.executeSP(proc, param, dt) Then

        End If
        Return dt
    End Function
    Private Function GetAllLike(ByVal proc As String, ByVal param() As Object) As DataTable
        Dim dt As New DataTable
        If Utils.executeSP(proc, param, dt) Then

        End If
        Return dt
    End Function
    Public Sub setGridPproperty(ByVal ColumnNamekey As String)
        Dim ds As New DataSet
        Dim dt As New DataTable

        If ProcName.Length > 0 Then
            ds.Tables.Clear()
            For i As Integer = 0 To ProcName.Length - 1
                dt = New DataTable
                dt = GetAllLike(ProcName(i), Params(i))
                If dt IsNot Nothing Then
                    dt.TableName = i.ToString
                    ds.Tables.Add(dt)
                End If
            Next
        End If
        If Not ds.Tables.Count = 2 Then
            Exit Sub
        End If
        If displaycolumn.Count = 0 Then
            For Each dc As DataColumn In ds.Tables(1).Columns
                displaycolumn.Add(dc.ColumnName)
            Next
        End If
        ds.CaseSensitive = True
        Dim dtrelation As DataRelation
        dtrelation = New DataRelation("relation", ds.Tables(0).Columns(ColumnNamekey), ds.Tables(1).Columns(ColumnNamekey))
        ds.Relations.Add(dtrelation)
        Dim newGridSource As DataGridSource = New DataGridSource(ds.Tables(0).DataSet, displaycolumn, nGroupcolumn)

        TreeGridView.DataSource = newGridSource
        Dim ba As New DataGridViewCellStyle()
        ba.Font = New Font(TreeGridView.Font, FontStyle.Bold)
        ba.BackColor = Color.AliceBlue
        Dim bb As New DataGridViewCellStyle()
        bb.Alignment = DataGridViewContentAlignment.MiddleRight
        'bb.BackColor = Color.Crimson
        For i As Integer = 0 To TreeGridView.ColumnCount - 1
            TreeGridView.Columns(i).HeaderText = StrConv(TreeGridView.Columns(i).HeaderText, VbStrConv.ProperCase)
        Next
        For Each dc As DataColumn In ds.Tables(1).Columns
            If Not dc.DataType.ToString = "System.String" Then
                Try
                    TreeGridView.Columns(dc.ColumnName).DefaultCellStyle = bb
                Catch ex As Exception

                End Try
            End If
        Next
        
        For j As Integer = 0 To TreeGridView.RowCount - 1
            For i As Integer = 0 To TreeGridView.ColumnCount - 1
                'HierarchicalGridView1.Rows(j).Cells(0).Style = bb
                If i > 0 Then
                    TreeGridView.Rows(j).Cells(i).Style = ba
                End If
            Next
        Next

    End Sub


End Class
